<template>
	<view>
		<!-- <button type="default" @click="method2">2</button> -->
		<view class="mainline1" v-cloak>
			欢迎回来,{{doctorinfo.doctorName}}{{doctorinfo.levelName}}!
		</view>
		<view class="separate"></view>
		<view class="mainline2">
			<u-row>
				<u-col span="6">
					<view class="mainline2text">
						待接诊的诊断
					</view>
				</u-col>
				<u-col span="6">
					<view class="mainline2text">
						已完成的诊断
					</view>
				</u-col>
			</u-row>
			<u-row>
				<u-col span="6">
					<view class="mainline2text" v-cloak>
<!-- 						{{indexa}} -->
						<u-count-to :start-val="0" end-val="0" :duration="2000" :use-easing="false" color=#ffffff></u-count-to>
					</view>
				</u-col>
				<u-col span="6">
					<view class="mainline2text" v-cloak>
<!-- 						{{indexb}} -->
						<u-count-to :start-val="0" end-val="4" :duration="2000" :use-easing="false" color=#ffffff></u-count-to>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="second-font mainline3">
			您的推送
		</view>
		<view class="separate"></view>
		<view v-if="list.length==0">
			<u-empty text="无内容" mode="list" class="mainempty"></u-empty>
		</view>
		<view>
				<u-swipe-action :show="item.show" :index="index" 
					v-for="(item, index) in list" :key="item.id" 
					@click="click" @open="open"
					:options="options">
					<view class="item u-border-bottom">
						<u-row>
							<u-col span="3">
								<u-icon name="chat" size="143" color=#1477fe></u-icon>
							</u-col>
							<u-col span="9">
								<view class="title-wrap">
									<text class="title u-line-2 second-font">{{ item.title }}</text>
								</view>
							</u-col>
						</u-row>
					</view>
				</u-swipe-action>
			</view>
		<u-tabbar :list="tabbar" active-color="#2979ff" inactive-color="#b9b9b9"></u-tabbar>
	</view>
</template>

<script>
	export default{
		methods:{
			method1(){
			},
			// method2(){
			// 	this.$goEasy.publish({
			// 	    channel: getApp().globalData.doctorinfo.doctorId, //替换为您自己的channel
			// 	    message: "Hello, GoEasy!" //替换为您想要发送的消息内容
			// 	});
			// },
			click(index, index1) {
				if(index1 == 0) {
					// this.list.splice(index, 1);
					getApp().globalData.infolist.splice(index, 1);
				}
				console.log(this.list)
			},
			open(index) {
				// 先将正在被操作的swipeAction标记为打开状态，否则由于props的特性限制，
				// 原本为'false'，再次设置为'false'会无效
				this.list[index].show = true;
				this.list.map((val, idx) => {
					if(index != idx) this.list[idx].show = false;
				})
			}
		},
		data(){
			return{
				tabbar:'',
				doctorinfo:{},
				indexa:0,
				indexb:0,
				disabled: false,
				btnWidth: 180,
				show: false,
				list:[],
				options: [
					{
						text: '删除',
						style: {
							backgroundColor: '#dd524d'
						}
					}
				]				
			}
		},
		onLoad(){
			this.$goEasy.subscribe({
				// channel: "吔我大菠萝啦", //替换为您自己的channel
			    channel: getApp().globalData.doctorinfo.doctorId, //替换为您自己的channel
			    onMessage: function (message) {
					getApp().globalData.infolist.push({
							title: message.content,
							// images: 'https://cdn.uviewui.com/uview/common/logo.png',
							show: false
					})
			        // console.log("Channel:" + message.channel + " content:" + message.content);
			    }
			});
			this.list=getApp().globalData.infolist
			uni.request({
			    url: getApp().globalData.hostip+'Demo/consult/findByDoc?id='+getApp().globalData.userinfo.nickName, 
			    data: {
			    },
			    success: (res) => {
			        console.log(res.data);
					for(var i=0;i<res.data.length;i++){
						res.data[i].drugIds=res.data[i].drugIds.split(',');
						for(var j=0;j< getApp().globalData.baseDrug.length;j++){
							for(var k=0;k<res.data[i].drugIds.length;k++){
								if(getApp().globalData.baseDrug[j].drugId.toString()==res.data[i].drugIds[k]){
									res.data[i].drugIds.splice(k,1, getApp().globalData.baseDrug[j].drugName)
								}
							}
						}
					}
					res.data.forEach(function(temp){
						getApp().globalData.patientlist.push(
						{
							'consultId':temp.consultId,
							'accountId':temp.accountId,
							'personName':temp.personName,
							'personCardType':'',
							'personCardId':temp.personCardId,
							'personGenderName':temp.personGenderName,
							'personBirthDate':'',
							'personAge':temp.personAge,
							'personPhoneNo':temp.personPhoneNo,
							'question':temp.question,
							'diagnosis':temp.diagnosis,
							'diagnosisIds':'',
							'drugIds':temp.drugIds,
							'photoIds':temp.photoIds.split(','),
							'consultStatus':temp.consultStatus,
							'consultCreateTime':temp.consultCreateTime.replace(".000+00:00","").replace("T"," "),
							'consultAcceptTime':'',
							'consultFinishTime':'',
							'prescriptions':[]
						})
					})
			    }
			});
			this.doctorinfo=getApp().globalData.doctorinfo;
			this.tabbar=
			[
				{
					iconPath: "home",
					selectedIconPath: "home-fill",
					text: '首页',
					pagePath:"/pages/doctor_mainpage"
				},
				{
					iconPath: "grid",
					selectedIconPath: "grid-fill",
					text: '配药',
					pagePath:"/pages/dispensing/doctor_dispensing"
				},
				// {
				// 	iconPath: "file-text",
				// 	selectedIconPath: "file-text-fill",
				// 	text: '处方',
				// 	pagePath:"/pages/prescription/doctor_prescriptionlist"
				// },
				{
					iconPath: "account",
					selectedIconPath: "account-fill",
					text: '我的',
					pagePath:"/pages/mine/doctor_mypage"
				},
			],
			console.log(getApp().globalData.userinfo)
				uni.request({
				    url: getApp().globalData.hostip+'Demo/doctor/upload', 
					method: 'POST',
				    data: {
						doctorId:getApp().globalData.userinfo.nickName,
						deptId:getApp().globalData.doctorinfo.deptId,
						doctorName:getApp().globalData.doctorinfo.doctorName,
						orgName:getApp().globalData.doctorinfo.orgName,
						heading:"https://vkceyugu.cdn.bspapp.com/VKCEYUGU-b32b5cb2-8bc8-483a-8465-e7b67cc35291/a07bb878-bc83-4a2c-b784-61e97267ee83.png",
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded',
					},
					fail:(fa) =>{
						console.log(fa)
					},
				    success: (res) => {
						console.log(res.data)
				    }
				});
			setTimeout(function () {
				var indexa=0;
				var indexb=0;
				getApp().globalData.patientlist.forEach(function(temp){
					console.log(temp.consultStatus)
					if(temp.consultStatus == "待接诊"){
						indexa++;
					}
					else if(temp.consultStatus == "已完成"){
						indexb++;
					}
				}),
				this.indexa=indexa;
				this.indexb=indexb;
				console.log("indexa"+this.indexa);
				console.log("indexb"+this.indexa)
			},1000)
		}
	}
</script>

<style scopped lang="scss">
	page{background-color: #f5f5f5;}
	.mainline1{
		width: 100%;
		background-color: #007AFF;
		color: #FFFFFF;
		font-size: 36rpx;
		padding: 24rpx;
	}
	.mainline2{
		width: 100%;
		background-color: #007AFF;
		color: #FFFFFF;
	}
	.mainline2text{
		text-align: center;
		font-size: 36rpx;
		font-weight: 800;
		margin-top: 20rpx;
	}
	.mainline3{
		// margin: 20rpx 20rpx;
		font-size: 32rpx;
		background-color: #FFFFFF;
		padding: 20rpx 20rpx;
	}
	// .mainline4{
	// 	margin-left: 20rpx;
	// }
	.item{
		padding: 20rpx 20rpx 20rpx 20rpx;
	}
	.title{
		padding: 20rpx;
		font-size: 32rpx;
	}
	.mainempty{
		padding:200rpx ;
	}
</style>
